package com.hyh.shiyanshiguanli.controller;

import com.hyh.shiyanshiguanli.constant.MessageConstant;
import com.hyh.shiyanshiguanli.domain.dto.*;
import com.hyh.shiyanshiguanli.domain.entity.Lib;
import com.hyh.shiyanshiguanli.domain.entity.Student;
import com.hyh.shiyanshiguanli.domain.result.PageResult;
import com.hyh.shiyanshiguanli.domain.result.Result;
import com.hyh.shiyanshiguanli.domain.vo.LibVO;
import com.hyh.shiyanshiguanli.domain.vo.StudentVO;
import com.hyh.shiyanshiguanli.service.ClassifyService;
import com.hyh.shiyanshiguanli.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hyh
 * @version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/student")
public class studentController {

    @Autowired
    StudentService studentService;


    @GetMapping("/page")
    public Result<StudentVO> page(MessageDTO messageDTO){
        log.info("学生分页查询{}",studentService);
        StudentVO studentVO = studentService.page(messageDTO);
        return Result.success(studentVO);
    }

    @PostMapping("/add")
    public Result addPublicInformation(@RequestBody StudentAddDTO studentAddDTO){
        log.info("添加studentAddDTO{}",studentAddDTO);
        studentService.add(studentAddDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<Student> selectById(@PathVariable Integer id){
        log.info("根据id查询LibManager{}",id);
        Student student = studentService.selectById(id);
        return Result.success(student);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody StudentUpdateDTO studentUpdateDTO){
        log.info("更新学生数据，id为{}",studentUpdateDTO.getId());
        studentService.updateById(studentUpdateDTO);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        log.info("删除id为{}的libManager",id);
        int delete = studentService.deleteById(id);
        if (delete == MessageConstant.SUCCESS){
            return Result.success();
        }
        else{
            return Result.error("不能删除");
        }

    }

}
